﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Caching.Memory;
using MyCode.Data.Models;
using MyCode.Data.VIewModels;
using MyCode.IOC;
using System.Linq;
namespace MyCode.Application.Impl
{
    public class Sys_ModuleImpl : ISys_Module, ITransientDependency
    {
        public NFineBaseContext db { get; set; }

        public Tuple<bool, string> AddOrUpdate()
        {
            throw new NotImplementedException();
        }

        public List<Sys_ModuleVM> GetAllModule()
        {
            var resultList = new List<Sys_ModuleVM>();
            var F_ParentId = "0";
            var parentList = db.SysModule.Where(m => m.FParentId == F_ParentId).ToList();
            var sublevelList = db.SysModule.Where(m => m.FParentId != F_ParentId).ToList();
            foreach (var item in parentList)
            {
                var entity = new Sys_ModuleVM();
                var list = sublevelList.Where(m => m.FParentId == item.FId).ToList();
                var subleve = new List<ChildrenVM>();
                foreach (var jtem in list)
                {
                    var childrenVM = new ChildrenVM();
                    childrenVM.alias = jtem.FUrlAddress;
                    childrenVM.ID = jtem.FId;
                    childrenVM.Name = jtem.FFullName;
                    childrenVM.CreatTime = jtem.FCreatorTime;
                    childrenVM.Iocn = jtem.FIcon;
                    subleve.Add(childrenVM);
                }
                entity.Name = item.FFullName;
                entity.alias = item.FUrlAddress;
                entity.ID = item.FId;
                entity.ChildrenVM = subleve;
                entity.Iocn = item.FIcon;
                resultList.Add(entity);
            }
            return resultList;
        }

        public List<Sys_ModuleVM> GetModule(string roleID, string type)
        {
            return null;
        }
    }
}
